package rak.r91.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.support.JdbcDaoSupport;

import rak.r91.data.ItemType;

public class JdbcItemTypeDao extends JdbcDaoSupport implements ItemTypeDao{
	
	public List<ItemType> getItemTypes() {
		return getJdbcTemplate().query("SELECT IT.item_type, IT.type_name FROM item_type IT WHERE level = 1 ORDER BY item_type",new itemMapper());
	}
	
	public List<ItemType> getItemSubTypes(int superTypeID) {		
		return getJdbcTemplate().query("SELECT IT.item_type, IT.type_name FROM item_type IT WHERE super_type_fk = "+superTypeID+" ORDER BY item_type;",new itemMapper());
	}
	
	private static final class itemMapper implements RowMapper<ItemType> {
	    public ItemType mapRow(ResultSet rs, int rowNum) throws SQLException {
	        ItemType item = new ItemType();
	        item.setItemTypeID(rs.getInt("item_type"));
	        item.setItemType(rs.getString("type_name"));
	        return item;
	    }
	}


}
